﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Manager : MonoBehaviour {
    // 玩家游戏对象
    public GameObject player;

    // 标题
    private GameObject title;

    bool isPlayIng = false;

    void Start () {
        // 搜索获取Title游戏对象
        title = GameObject.Find ("Title");
    }

    void Update () {
        // 游戏中之外、按X键开始游戏
        if (IsPlaying () == false && Input.GetKeyDown (KeyCode.X)) {
            GameStart ();
        }
    }

    void GameStart () {
        // 游戏开始时、隐藏标题，并且生成Player

        isPlayIng = true;
        title.SetActive (!isPlayIng);
        Instantiate (player, player.transform.position, player.transform.rotation);
        FindObjectOfType<Score>();
    }

    public void GameOver () {
        // 游戏结束时、显示标题
        isPlayIng = false;
        title.SetActive (!isPlayIng);
        FindObjectOfType<Score>().Save();
    }

    public bool IsPlaying () {
        // 用标题的显示不显示来判断是否处在游戏中
        return isPlayIng;
    }
}